import config from '@/config/config'
import {formatDate} from '@/utils/util'
import Cookies from 'js-cookie'

const TokenKey = 'element-window-partner' + formatDate(new Date(), 'yyyyMM') + '-' + getTokenSuffix()

// 根据不同环境进行不同的token记录
export function getTokenSuffix() {
  let url = config.baseUrl.prod
  let tokenSuffix
  if (process.env.NODE_ENV === 'development') {
    tokenSuffix = 'dev'
  } else if (url.includes('/blhcSelfShop')) {
    tokenSuffix = 'prod'
  } else if (url.includes('/blhc_selfShopTest')) {
    tokenSuffix = 'test'
  } else {
    tokenSuffix = 'dev'
  }
  return tokenSuffix
}

export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}
